package com.example.sa.myapp.shopping_cart;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;

import com.example.sa.myapp.R;
import com.example.sa.myapp.androidUtil.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class ShoppCar_Fragment extends BaseFragment {

    private List<Shop> shopList = new ArrayList<>();
    private  ShopAdapter shopAdapter;
    RecyclerView recyclerView;
    private CheckBox AllSel;

    public ShoppCar_Fragment() {
        Shop adminTest = new Shop("联想办公本","联想小新Air 14(i5-8250U/8GB/256GB/MX150)", R.drawable.q, 5799, 20);
        shopList.add(adminTest);
        Shop sp[] = new Shop[10];
        for (int i = 0; i < 10; i++) {
            sp[i]= new Shop("苹果" + i, " 联想扬天V310(i5-6200U/4GB/500GB)", R.drawable.q, 3799, 10);
            shopList.add(sp[i]);
        }
    }

    class AllCheckListener implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            CheckBox all = (CheckBox)v;
            if (all.isChecked())
                ShopAdapter.setAllCheckBox(true);
            else
                ShopAdapter.setAllCheckBox(false);
            shopAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        recyclerView = getActivity().findViewById(R.id.rlv_shop_car_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        AllSel = getActivity().findViewById(R.id.cb_shop_car_allsel);
        AllSel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点击全选
                AllCheckListener allCheckListener=new AllCheckListener();
                AllSel.setOnClickListener(allCheckListener);
                shopAdapter.notifyDataSetChanged();
            }
        });

        shopAdapter = new ShopAdapter(getContext(), shopList);
        recyclerView.setAdapter(shopAdapter);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_shopp_car, container, false );
    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_shopp_car;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

}
